package com.xushu.compent;

import com.xushu.iocbeanlifecicle.Car;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

/***
 * 作用：动态注册BeanDefinition 先
 * 调用时机： Ioc加载时注册BeanDefinition 的时候会调用
 */
@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {


        RootBeanDefinition beanDefinition = new RootBeanDefinition(Car.class);
        registry.registerBeanDefinition("car",beanDefinition);
    }









    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
